/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.scheduling;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DAGRole {
    private List<String> guest;                               // 角色guest列表
    private List<String> host;                                // 角色host列表
    private List<String> arbiter;                             // 角色arbiter列表


    public List<String> getGuest() {
        return guest;
    }

    public void setGuest(List<String> guest) {
        this.guest = guest;
    }

    public List<String> getHost() {
        return host;
    }

    public void setHost(List<String> host) {
        this.host = host;
    }

    public List<String> getArbiter() {
        return arbiter;
    }

    public void setArbiter(List<String> arbiter) {
        this.arbiter = arbiter;
    }

    public static DAGRole fromJson(String json) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        DAGRole obj = mapper.readValue(json, DAGRole.class);
        return obj;
    }

    public Map<String, List<String>> toMap(){
        HashMap<String, List<String>> map = new HashMap<>();
        map.put("guest", guest);
        map.put("host", host);
        map.put("arbiter", arbiter);
        return map;
    }

    // 结构体转换为json字符串
    public String toJson() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(this.toMap());
        return json;
    }
}
